﻿unit Form_BaseWindow;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IBDatabase{, Forms}, Menus, ComCtrls,  ExtCtrls, JvExControls,
  JvGradient, JvgPage, JvgTypes, JvGradientHeaderPanel, JvTypes;

type
  TComponentState = (csLaunch, csVisible, csEnabled);

  TGradientStyle  = (gsHorizontal, gsVertical, gsDiagonalLeftRight, gsDiagonalRightLeft, gsElipsa);

  TColorQuad = record
    Red, Green, Blue, Alpha: Byte;
  end;

  TLargeColorQuad = record
    Red, Green, Blue, Alpha: Longint;
  end;

  T32bitScanLineElement = record
    Blue, Green, Red, Alpha: Byte;
  end;

  P32bitQuadScanLine = ^T32bitQuadScanLine;
  T32bitQuadScanLine = array[0..High(Word) div 3] of T32bitScanLineElement;

const
  regKey = 'SOFTWARE\Tarbonus\AsystentBHP\4.0';

type
  TfrmBaseWindow = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormShow(Sender: TObject);
    procedure MenuFirstBarDrawItem(Sender: TObject; ACanvas: TCanvas;
      ARect: TRect; Selected: Boolean);
    procedure MenuLastBarDrawItem(Sender: TObject; ACanvas: TCanvas;
      ARect: TRect; Selected: Boolean);
    procedure PopupMenuFirstBarDrawItem(Sender: TObject; ACanvas: TCanvas;
      ARect: TRect; Selected: Boolean);
    procedure PopupMenuMiddleBarDrawItem(Sender: TObject; ACanvas: TCanvas;
      ARect: TRect; Selected: Boolean);
    procedure PopupMenuLastBarDrawItem(Sender: TObject; ACanvas: TCanvas;
      ARect: TRect; Selected: Boolean);
    procedure PopupMenuHorizontalBarDrawItem(Sender: TObject; ACanvas: TCanvas;
      ARect: TRect; Selected: Boolean);
    procedure PopupMenuHorizontalDrawItem(Sender: TObject; ACanvas: TCanvas;
      ARect: TRect; Selected: Boolean);
    procedure PageControlFirstDrawTab(Control: TCustomTabControl;
      TabIndex: Integer; const Rect: TRect; Active: Boolean);
    procedure JvgPageControlFirstDrawTab(Control: TCustomTabControl;
      TabIndex: Integer; const Rect: TRect; Active: Boolean);
    procedure EditKeyPressNumericOnly(Sender: TObject; var Key: Char);
    procedure EditKeyPressNumericREGONPESEL(Sender: TObject; var Key: Char);
    procedure EditKeyPressNumericInteger(Sender: TObject; var Key: Char);
    procedure EditKeyPressNumericFloat(Sender: TObject; var Key: Char);
    procedure EditKeyPressNumericNIP(Sender: TObject; var Key: Char);
    procedure EditKeyPressNumericTime(Sender: TObject; var Key: Char);
    procedure EditKeyPressCharsOnly(Sender: TObject; var Key: Char);
    procedure EditKeyPressPostCode(Sender: TObject; var Key: Char);
    procedure EditKeyPressCharsAll(Sender: TObject; var Key: Char);
    procedure EditEnter(Sender :TObject);
    procedure EditExit(Sender :TObject);
    procedure EditExitPostCode(Sender :TObject);
    procedure EditKeyPressNumericOnlyPostCode(Sender: TObject; var Key: Char);
    procedure EditKeyPressNameStreetChars(Sender: TObject; var Key: Char);
  private
    FDatabase: TIBDatabase;
    fUserID: integer;
    FTransaction: TIBTransaction;
    fNewConnection: boolean;
    FPrevCaption: WideString;    // pole wykorzystywane do wprowadzania przed wartoscia Caption dodatkowego tekstu
    FDrawBuffer: TBitmap;
    procedure SetTransaction(const Value: TIBTransaction);
    function GetTransaction: TIBTransaction;
    procedure LoadWindowSize; //ładuje wielkośc okna
    procedure SaveWindowSize;
    procedure SetPrevCaption(const Value: WideString); //zapisuje wielkośc okna
    function GetDrawBuffer: TBitmap;
  protected
    procedure SetDatabase(const Value: TIBDatabase);virtual;
    procedure SetUserID(const Value: integer); virtual;
  public
    MaximizeOnDefault : Boolean;
    ColorEditBeforEnter :TColor;
    property Database: TIBDatabase read FDatabase write SetDatabase;
    constructor Create; reintroduce; virtual;
    destructor Destroy; override;
    property Transaction: TIBTransaction read GetTransaction;
    property UserID: integer read FUserID write SetUserID;
    property PrevCaption: WideString read FPrevCaption write SetPrevCaption;
    procedure DrawGradient(Canvas: TCanvas; ARect: TRect; StartingColor,
      EndingColor: TColor; Style: TGradientStyle);
    property DrawBuffer: TBitmap read GetDrawBuffer;
    function refDrawMenu(MenuItems :TMenuItem): boolean;
    procedure DrawMainMenu(MainMenu :TMainMenu);
    procedure DrawPopupMenu(PopupMenu :TPopupMenu);
    procedure DrawPageControl(PageControl :TPageControl);
    procedure DrawJvgPageControl(PageControl :TJvgPageControl);
    procedure DrawComponents;
    function RyzykoAnalizaPN(var iRyzyko : integer; sKrotnosc, sWynikPomiaru, sTypCzynnika : String) : AnsiString;
  published
  end;

function RectWidth(const ARect: TRect): Integer;
function RectHeight(const ARect: TRect): Integer;
function RectInRect(const Source, Target: TRect): Boolean;
function BitmapRect(const ABitmap: TBitmap): TRect;
procedure DrawGradient2(ABitmap: TBitmap; ACanvas: TCanvas; ARect: TRect; ColorFrom, ColorTo: TColor; Style: TGradientStyle);
function RGB2(Red, Green, Blue: Byte; Alpha: Byte = $00): TColor;

var
  NilRect: TRect = (Left: 0; Top: 0; Right: 0; Bottom: 0);

var
  frmBaseWindow: TfrmBaseWindow;

implementation

{$R *.DFM}

uses
  Registry, TypInfo, StdCtrls, Math;
  {Menus,cxGridDBDataDefinitions}

constructor TfrmBaseWindow.Create;
begin
  MaximizeOnDefault := False;  //wiekszosc okien nie maksymalizowac
  inherited Create(Application);

  if (Screen.PixelsPerInch = 120) then
    ScaleBy(105, 100);
end;

destructor TfrmBaseWindow.Destroy;
begin

  if fNewConnection then
    FTransaction.Free;

  inherited;
end;


function TfrmBaseWindow.GetTransaction: TIBTransaction;
begin
  if not assigned(fTransaction) then
  begin
    fNewConnection := true;
    fTransaction := TIBTransaction.Create(nil);
    fTransaction.DefaultDatabase := FDatabase;
    fTransaction.AutoStopAction := saCommit;
    FTransaction.Params.Add('read_committed');
    FTransaction.Params.Add('rec_version');
    FTransaction.Params.Add('nowait');
    // dodane na czuja
    //FTransaction.StartTransaction;
    // koniec dodane
  end;

  result := FTransaction;
end;

procedure TfrmBaseWindow.LoadWindowSize;
var
  registry: TRegistry;
begin
  registry := TRegistry.Create;
  registry.RootKey := HKEY_CURRENT_USER;
  try
    registry.OpenKey(regKey+'\FormPlacement\'+Self.Name,false);

    SetBounds(Screen.Monitors[0].Left + ((Screen.Monitors[0].Width - Width) div 2),
              Screen.Monitors[0].Top + ((Screen.Monitors[0].Height - Height) div 2),
              Width, Height);

    if (not registry.ValueExists('FormMaximized')) and (MaximizeOnDefault) then
      WindowState:=wsMaximized;       // maksymalizuje domyslnie niektore okna

    if registry.ValueExists('FormMaximized') and (registry.ReadBool('FormMaximized')) then
      WindowState:=wsMaximized
      else
      begin
        if registry.ValueExists('FormLeft') then
          Left := registry.ReadInteger('FormLeft');

        if registry.ValueExists('FormTop') then
          Top := registry.ReadInteger('FormTop');

        if (BorderStyle<>bsDialog) then
        begin
          if registry.ValueExists('FormWidth') then
            Width := registry.ReadInteger('FormWidth');

          if registry.ValueExists('FormHeight') then
            Height := registry.ReadInteger('FormHeight');
        end;

      end;
  finally
    registry.Free;
  end;
  // ponizej zmniejszanie okien
  if screen.Height < self.Height then
  begin
    self.Height := screen.Height;
  end;
//  if screen.Width < self.Width then
//  begin
//    self.Width := screen.Width;
//  end;
end;

procedure TfrmBaseWindow.SetTransaction(const Value: TIBTransaction);
begin
  FTransaction := Value;
  fNewConnection := false;
end;

procedure TfrmBaseWindow.SaveWindowSize;
var
  registry: TRegistry;
begin
  registry := TRegistry.Create;
  registry.RootKey := HKEY_CURRENT_USER;
  try
    registry.OpenKey(regKey+'\FormPlacement\'+Self.Name,true);
    registry.WriteBool('FormMaximized',WindowState=wsMaximized);
    if (WindowState<>wsMaximized) then
    begin
      registry.WriteInteger('FormLeft',Left);
      registry.WriteInteger('FormTop',Top);
      if (BorderStyle<>bsDialog) then
      begin
        registry.WriteInteger('FormWidth',Width);
        registry.WriteInteger('FormHeight',Height);
      end;
    end;
  finally
    registry.Free;
  end;
end;

procedure TfrmBaseWindow.SetDatabase(const Value: TIBDatabase);
begin
  Fdatabase := Value;
end;

procedure TfrmBaseWindow.SetUserID(const Value: integer);
begin
  FUserID := Value;
end;


procedure TfrmBaseWindow.FormCreate(Sender: TObject);
begin
  Application.UpdateFormatSettings := False;
  DateSeparator := '-';
  ShortDateFormat := 'yyyy-mm-dd';
  LongDateFormat := 'yyyy-mm-dd';

end;

procedure TfrmBaseWindow.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  i : Integer;
begin
  if (ssShift in Shift) and (ssAlt in Shift) and (ssCtrl in Shift) and (Key = 88) then
  begin
    for i:=0 to ComponentCount-1 do
    begin
      if Components[i].InheritsFrom(TControl) then
      begin
        TControl(Components[i]).Hint := TControl(Components[i]).Name;
        TControl(Components[i]).ShowHint := True;
      end;
    end;
    Caption := Self.name;
  end;
end;

procedure TfrmBaseWindow.SetPrevCaption(const Value: WideString);
begin
  FPrevCaption := Value;
end;

procedure TfrmBaseWindow.DrawPageControl(PageControl :TPageControl);
begin
  PageControl.OwnerDraw := true;
  PageControl.OnDrawTab := PageControlFirstDrawTab;
end;

procedure TfrmBaseWindow.DrawJvgPageControl(PageControl :TJvgPageControl);
begin
  PageControl.OwnerDraw := true;
  PageControl.OnDrawTab := JvgPageControlFirstDrawTab;
  PageControl.TabSelectedStyle.Gradient.FromColor := Self.Color;
  PageControl.TabSelectedStyle.Gradient.ToColor := clCream;
  PageControl.TabSelectedStyle.Gradient.Orientation := fgdHorzConvergent;
  PageControl.TabSelectedStyle.Font.Color := clBlack;
  PageControl.TabSelectedStyle.Gradient.Active := true;
  PageControl.TabStyle.Gradient.FromColor := clCream;
  PageControl.TabStyle.Gradient.ToColor := Self.Color;
  PageControl.TabStyle.Gradient.Orientation := fgdHorzConvergent;
  PageControl.TabStyle.Font.Color := clGreen;
  PageControl.TabStyle.Gradient.Active := true;
end;

procedure TfrmBaseWindow.EditEnter(Sender: TObject);
begin
  if Sender is TEdit then begin
    with Sender as TEdit do begin
      ColorEditBeforEnter := Color;
      Color := RGB(255,244,154);
    end;
  end;
  if Sender is TMemo then begin
    with Sender as TMemo do begin
      ColorEditBeforEnter := Color;
      Color := RGB(255,244,154);
    end;
  end;
end;

procedure TfrmBaseWindow.EditExit(Sender :TObject) ;
begin
  if Sender is TEdit then begin
    with Sender as TEdit do begin
      Color := ColorEditBeforEnter;
    end;
  end;
  if Sender is TMemo then begin
    with Sender as TMemo do begin
      Color := ColorEditBeforEnter;
    end;
  end;
end;

procedure TfrmBaseWindow.EditKeyPressNumericOnlyPostCode(Sender: TObject; var Key: Char);
var
  i: Integer;
  ile: Integer;
  str : string;
  iSelStart :integer;
begin
  iSelStart := TEdit(Sender).SelStart;

  if not (Key in ['0'..'9','-',','] + [#8] + [#32] + [#13]) then begin
    Key:=#0;
    Exit;
  end;

  if TEdit(Sender).SelText <> '' then begin
    Key:=   Key;
    Exit;
  end;

  TEdit(Sender).SelLength := 0;
  if (Key <> #0 ) and (Sender is TEdit) then
    if (Key = '-') and (Length(TEdit(Sender).Text)<2) then
        Key:=#0;
  if (Key = '-') and (Length(TEdit(Sender).Text)>2) then begin
    ile := 1;
    for i := 1 to Length(TEdit(Sender).Text) do begin
      if TEdit(Sender).Text[i] = '-' then
        Inc(ile);
        if ile>1 then begin
          key:=#0;
          Exit;
        end;
    end;
  end;
  if (Key <> #0) then begin
    //usuwamy znak "-" jesli jest na złej pozycji

    if (Length(TEdit(Sender).Text) > 1) and (Pos('-',TEdit(Sender).Text)<1) and not(Key in [#8,'-']) then begin
      str := TEdit(Sender).Text;
      iSelStart := TEdit(Sender).SelStart;
      Insert('-', str, 3);
      TEdit(Sender).SelLength := 0;
      TEdit(Sender).Text := str;
      if(Length(str)<3) then
        TEdit(Sender).SelStart := Length(str)
      else
        TEdit(Sender).SelStart := iSelStart+1;
      //Length(str);
      if (Pos('-',TEdit(Sender).Text)<3) or (Pos('-',TEdit(Sender).Text)>3) then begin
      str := TEdit(Sender).Text;
      Delete(str,Pos('-',TEdit(Sender).Text),1);
      TEdit(Sender).SelLength := 0;
      TEdit(Sender).Text := str;
      TEdit(Sender).SelStart := iSelStart; //Length(str);
    end;
    end;
  end;

  //długosc nie moze przekraczac 6 znaków (2czyfry + znak minus"-" + 3 cyfry)
  if (Length(TEdit(Sender).Text) > 5) and not(Key in [#8] + [#13]) then Key := #0;
end;

procedure TfrmBaseWindow.EditExitPostCode(Sender: TObject);
var
  str : string;
begin
  if Sender is TEdit then begin
    if (Length(TEdit(Sender).Text) > 2) then begin
      str := TEdit(Sender).Text;
      if Pos('-',str)>0 then
        exit;
      while Pos(' ',str)>0 do
        delete(str,Pos(' ',str),1);
      Insert('-',str,3);
      TEdit(Sender).Text := str;
    end;
    TEdit(Sender).Color := ColorEditBeforEnter;
  end;
end;

procedure TfrmBaseWindow.DrawComponents;
var
  i: Integer;
begin
  self.Color := $00C0B0B0;
  for i:=0 to ComponentCount -1 do begin
    if Components[i] is TMainMenu then
      DrawMainMenu(Components[i] as TMainMenu);
    if Components[i] is TPopupMenu then
      DrawPopupMenu(Components[i] as TPopupMenu);
    if Components[i] is TPageControl then
      DrawPageControl(Components[i] as TPageControl);
    if Components[i] is TPanel then begin
      TPanel(Components[i]).ParentBackground := true;
      TPanel(Components[i]).Color := Self.Color;
      TPanel(Components[i]).BevelOuter := bvNone;
      TPanel(Components[i]).Caption := ' ';
    end;
    if Components[i] is TScrollBox then begin
      TScrollBox(Components[i]).ParentBackground := true;
      TScrollBox(Components[i]).Color := clBtnFace;
    end;
    if Components[i] is TJvGradient then begin
      TJvGradient(Components[i]).EndColor := clCream;
      TJvGradient(Components[i]).StartColor := Self.Color;
      TJvGradient(Components[i]).Style := grPyramid;
    end;
    if Components[i] is TJvgPageControl then begin
      DrawJvgPageControl(Components[i] as TJvgPageControl);
      TJvgPageControl(Components[i]).ActivePageIndex := 0;
    end;
    if Components[i] is TLabel then begin
      TLabel(Components[i]).Caption := ' ' + TLabel(Components[i]).Caption;
      TLabel(Components[i]).Transparent := true;
    end;
    if Components[i] is TPageControl then begin
      TPageControl(Components[i]).ActivePageIndex := 0;
    end;
    if Components[i] is TCoolBar then
      TCoolBar(Components[i]).Color := Self.Color;
    if Components[i] is TToolBar then begin
      TToolBar(Components[i]).DrawingStyle := ComCtrls.dsGradient;
      TToolBar(Components[i]).GradientEndColor := Self.Color;
      TToolBar(Components[i]).GradientStartColor := clCream;
    end;
    if Components[i] is TEdit then begin
      if not TEdit(Components[i]).ReadOnly then begin
        TEdit(Components[i]).OnEnter := EditEnter;
        TEdit(Components[i]).OnExit := EditExit;
      end;
    end;
     if Components[i] is TMemo then begin
      TMemo(Components[i]).OnEnter := EditEnter;
      TMemo(Components[i]).OnExit := EditExit;
    end;
    if Components[i] is TJvGradientHeaderPanel then begin
      TJvGradientHeaderPanel(Components[i]).GradientStartColor := Self.Color;
      TJvGradientHeaderPanel(Components[i]).GradientEndColor := clCream;
      TJvGradientHeaderPanel(Components[i]).LabelCaption := '   ';
      TJvGradientHeaderPanel(Components[i]).GradientSteps := 500;
      TJvGradientHeaderPanel(Components[i]).GradientStyle := grMount;
    end;
    if Components[i] is TTabSheet then begin
      TTabSheet(Components[i]).Caption := ' ' + TTabSheet(Components[i]).Caption + '  ';
    end;
  end;
end;
procedure TfrmBaseWindow.FormShow(Sender: TObject);
var
  i: Integer;
begin
  if (FPrevCaption <> '') and (Caption <> '') then
    Caption := FPrevCaption + ' - '+ Caption
  else if (FPrevCaption <> '') and (Caption = '') then
    Caption := FPrevCaption;
//  DrawComponents;
//  Application.ProcessMessages;
end;

function TfrmBaseWindow.GetDrawBuffer: TBitmap;
begin
  if not Assigned(FDrawBuffer) then
    FDrawBuffer := TBitmap.Create;
  Result := FDrawBuffer;
end;

procedure TfrmBaseWindow.DrawGradient(Canvas: TCanvas; ARect: TRect; StartingColor,
  EndingColor: TColor; Style: TGradientStyle);
begin
  DrawBuffer.Height := RectHeight(ARect);
  DrawBuffer.Width := RectWidth(ARect);
  DrawGradient2(DrawBuffer, nil, BitmapRect(DrawBuffer), startingColor, EndingColor, Style);
  Canvas.Draw(ARect.Left, ARect.Top, DrawBuffer); // copy the buffer
  DrawBuffer.Height := 0;
  DrawBuffer.Width := 0;
end;

procedure TfrmBaseWindow.MenuFirstBarDrawItem(Sender: TObject; ACanvas: TCanvas;
  ARect: TRect; Selected: Boolean);
var R:TRect;
    MenuItemText:string;
begin
     R := ARect;
    //R.Left := R.Right - ACanvas.TextWidth(AMenuItem.Hint) - 15;
     //R.Right:=Form1.Width-2;
     DrawGradient(ACanvas, R, $00C0B0B0, clWhite, gsVertical);

     with Sender as  TMenuItem do
     begin
        MenuItemText:=Caption;
     end;

    ACanvas.Brush.Color := clYellow;
    ACanvas.Brush.Style := bsClear;
     R := ARect;
     R.Left:=R.Left+8;
      DrawText(ACanvas.Handle, PChar(MenuItemText), Length(MenuItemText), R, 0);

end;

procedure TfrmBaseWindow.MenuLastBarDrawItem(Sender: TObject;
  ACanvas: TCanvas; ARect: TRect; Selected: Boolean);
var R:TRect;
    MenuItemText:string;
begin
     R := ARect;
    //R.Left := R.Right - ACanvas.TextWidth(AMenuItem.Hint) - 15;
     R.Right:= Width-2;
     DrawGradient(ACanvas, R, $00C0B0B0, clWhite, gsVertical);

     with Sender as  TMenuItem do
     begin
        MenuItemText:=Caption;
     end;

     ACanvas.Brush.Color := clYellow;
     ACanvas.Brush.Style := bsClear;
     R := ARect;
     R.Left:=R.Left+8;
      DrawText(ACanvas.Handle, PChar(MenuItemText), Length(MenuItemText), R, 0);

end;

procedure TfrmBaseWindow.PopupMenuFirstBarDrawItem(Sender: TObject; ACanvas: TCanvas;
  ARect: TRect; Selected: Boolean);
var
  R:TRect;
  MenuItemText:string;
begin
     R := ARect;
    //R.Left := R.Right - ACanvas.TextWidth(AMenuItem.Hint) - 15;
     //R.Right:=Form1.Width-2;
     DrawGradient(ACanvas, R,  $00C0B0B0, clWhite, gsVertical);

     with Sender as  TMenuItem do
     begin
        MenuItemText:=Caption;
     end;
    if Selected then
       ACanvas.Font.Style := [fsItalic]
    else
       ACanvas.Font.Style := [];
    ACanvas.Font.Color := clBlack;
    ACanvas.Brush.Color := clBlack;
    ACanvas.Brush.Style := bsClear;



     R := ARect;
     R.Left:=R.Left+8;
      DrawText(ACanvas.Handle, PChar(MenuItemText), Length(MenuItemText), R, 0);

end;

procedure TfrmBaseWindow.PopupMenuMiddleBarDrawItem(Sender: TObject; ACanvas: TCanvas;
  ARect: TRect; Selected: Boolean);
var R:TRect;
    MenuItemText:string;
begin
     R := ARect;
    //R.Left := R.Right - ACanvas.TextWidth(AMenuItem.Hint) - 15;
     //R.Right:=Form1.Width-2;
     DrawGradient(ACanvas, R, clWhite, clWhite, gsVertical);

     with Sender as  TMenuItem do
     begin
        MenuItemText:=Caption;
     end;
    if Selected then
       ACanvas.Font.Style := [fsItalic]
    else
       ACanvas.Font.Style := [];
    ACanvas.Font.Color := clBlack;
    ACanvas.Brush.Color := clBlack;
    ACanvas.Brush.Style := bsClear;
     R := ARect;
     R.Left:=R.Left+8;
      DrawText(ACanvas.Handle, PChar(MenuItemText), Length(MenuItemText), R, 0);

end;

procedure TfrmBaseWindow.PopupMenuLastBarDrawItem(Sender: TObject; ACanvas: TCanvas;
  ARect: TRect; Selected: Boolean);
var R:TRect;
    MenuItemText:string;
begin
     R := ARect;
    //R.Left := R.Right - ACanvas.TextWidth(AMenuItem.Hint) - 15;
     //R.Right:=Form1.Width-2;
     DrawGradient(ACanvas, R, clWhite, $00C0B0B0, gsVertical);

     with Sender as  TMenuItem do
     begin
        MenuItemText:=Caption;
     end;
    if Selected then
       ACanvas.Font.Style := [fsItalic]
    else
       ACanvas.Font.Style := [];
    ACanvas.Font.Color := clBlack;
    ACanvas.Brush.Color := clBlack;
    ACanvas.Brush.Style := bsClear;
     R := ARect;
     R.Left:=R.Left+8;
      DrawText(ACanvas.Handle, PChar(MenuItemText), Length(MenuItemText), R, 0);

end;

procedure TfrmBaseWindow.PopupMenuHorizontalBarDrawItem(Sender: TObject; ACanvas: TCanvas;
  ARect: TRect; Selected: Boolean);
var R:TRect;
    MenuItemText:string;
begin
     R := ARect;
    //R.Left := R.Right - ACanvas.TextWidth(AMenuItem.Hint) - 15;
     //R.Right:=Form1.Width-2;
     DrawGradient(ACanvas, R, clWhite, $00C0B0B0, gsHorizontal);

     with Sender as  TMenuItem do
     begin
        MenuItemText:=Caption;
     end;
    if Selected then
       ACanvas.Font.Style := [fsItalic]
    else
       ACanvas.Font.Style := [];
    ACanvas.Font.Color := clBlack;
    ACanvas.Brush.Color := clBlack;
    ACanvas.Brush.Style := bsClear;
     R := ARect;
     R.Left:=R.Left+8;
      DrawText(ACanvas.Handle, PChar(MenuItemText), Length(MenuItemText), R, 0);
end;

procedure TfrmBaseWindow.PopupMenuHorizontalDrawItem(Sender: TObject; ACanvas: TCanvas;
  ARect: TRect; Selected: Boolean);
var R:TRect;
    MenuItemText:string;
begin
     R := ARect;
    //R.Left := R.Right - ACanvas.TextWidth(AMenuItem.Hint) - 15;
     //R.Right:=Form1.Width-2;
     DrawGradient(ACanvas, R, clWhite, $00C0B0B0, gsHorizontal); //gsVertical);

     with Sender as  TMenuItem do
     begin
        MenuItemText:=Caption;
     end;
    if Selected then
      ACanvas.Font.Style := [fsItalic]
    else
      ACanvas.Font.Style := [];

    ACanvas.Font.Color := clBlack;

    ACanvas.Brush.Color := clYellow;
    ACanvas.Brush.Style := bsClear;
     R := ARect;
     R.Left:=R.Left+8;
      DrawText(ACanvas.Handle, PChar(MenuItemText), Length(MenuItemText), R, 0);

end;

function TfrmBaseWindow.refDrawMenu(MenuItems :TMenuItem): boolean;
var
  I: Integer;
begin
  if MenuItems.Count > 0 then begin

    for I := 0 to MenuItems.Count - 1 do begin

      MenuItems.Items[i].OnDrawItem := PopupMenuHorizontalDrawItem;
      if MenuItems.Items[i].Count > 0 then begin
        MenuItems.Items[i].Caption := MenuItems.Items[i].Caption + '    ';
        refDrawMenu(MenuItems.Items[i])
      end;
    end;
  end; //else
  Result := true;
end;

procedure TfrmBaseWindow.DrawMainMenu(MainMenu :TMainMenu);
var
  i: Integer;
begin
  MainMenu.OwnerDraw := true;
  if MainMenu.Items.Count>0 then begin
    for i := 0 to MainMenu.Items.Count - 1 do begin
     MainMenu.Items.Items[i].OnDrawItem := MenuFirstBarDrawItem;
     refDrawMenu(MainMenu.Items.Items[i]);
    end;
    MainMenu.Items.Items[MainMenu.Items.Count-1].OnDrawItem := MenuLastBarDrawItem;
 end;
end;

procedure TfrmBaseWindow.DrawPopupMenu(PopupMenu :TPopupMenu);
var
  i: Integer;
begin
  PopupMenu.OwnerDraw := true;
  if PopupMenu.Items.Count>0 then begin
    for i := 0 to PopupMenu.Items.Count - 1 do begin
     PopupMenu.Items.Items[i].OnDrawItem := PopupMenuHorizontalDrawItem;
     if PopupMenu.Items[i].Count > 0 then begin
        PopupMenu.Items[i].Caption := PopupMenu.Items[i].Caption + '    ';
        refDrawMenu(PopupMenu.Items.Items[i]);
     end;
    end;
 end;
end;

procedure TfrmBaseWindow.EditKeyPressNumericOnly(Sender: TObject; var Key: Char);
begin
  if not (Key in ['0'..'9','-',',','(',')','+'] + [#8] + [#32] + [#13]) then Key:=#0;
end;

procedure TfrmBaseWindow.EditKeyPressNumericREGONPESEL(Sender: TObject; var Key: Char);
begin
  if not (Key in ['0'..'9'] + [#8] + [#13]) then Key:=#0;
end;

procedure TfrmBaseWindow.EditKeyPressNumericInteger(Sender: TObject; var Key: Char);
begin
  if not (Key in ['0'..'9'] + [#8] + [#13]) then Key:=#0;
end;

procedure TfrmBaseWindow.EditKeyPressNumericFloat(Sender: TObject; var Key: Char);
begin
  if not (Key in ['0'..'9',','] + [#8] + [#32] + [#13]) then Key:=#0;
end;

procedure TfrmBaseWindow.EditKeyPressNumericNIP(Sender: TObject; var Key: Char);
begin
  if not (Key in ['0'..'9'] + [#8] + [#13]) then Key:=#0;
  //if (Key <> #0) and (Sender is TEdit) then  begin
    //if Length((Sender as TEdit).Text) > 13 then
    //  Key:=#0;
  //end;
end;

procedure TfrmBaseWindow.EditKeyPressNumericTime(Sender: TObject; var Key: Char);
begin
  if not (Key in ['0'..'9',':','.'] + [#8] + [#32]) then Key:=#0;
end;

procedure TfrmBaseWindow.EditKeyPressPostCode(Sender: TObject; var Key: Char);
begin
  if (not (Key in ['0'..'9','-'] + [#8])) or ((Length(TEdit(Sender).Text) >= 5) and (Key <> #8)) then Key:=#0;
end;

procedure TfrmBaseWindow.EditKeyPressCharsAll(Sender: TObject; var Key: Char);
begin
  Key := Key;
end;

procedure TfrmBaseWindow.EditKeyPressCharsOnly(Sender: TObject; var Key: Char);
begin
  //if not (Key in ['A'..'Z','a'..'z','ę','ó','ą','ś','ł','ż','ź','ć','ń','Ę','Ó','Ą','Ś','Ł','Ż','Ź','Ć','Ń','-',',','.'] + [#8] + [#32]) then Key:=#0;
  case Key of
    'A'..'Z','Ę','Ó','Ą','Ś','Ł','Ż','Ź','Ć','Ń': Key:=Key;
    'a'..'z','ę','ó','ą','ś','ł','ż','ź','ć','ń': Key:=Key;
    #8: Key:=Key;
    #32: Key:=Key;
    '.': Key:=Key;
    '-': Key:=Key;
    else
      Key:=#0;
  end;
end;

procedure TfrmBaseWindow.EditKeyPressNameStreetChars(Sender: TObject; var Key: Char);
begin
  //if not (Key in ['A'..'Z','a'..'z','ę','ó','ą','ś','ł','ż','ź','ć','ń','Ę','Ó','Ą','Ś','Ł','Ż','Ź','Ć','Ń','-',',','.'] + [#8] + [#32]) then Key:=#0;
  case Key of
    'A'..'Z','Ę','Ó','Ą','Ś','Ł','Ż','Ź','Ć','Ń': Key:=Key;
    'a'..'z','ę','ó','ą','ś','ł','ż','ź','ć','ń': Key:=Key;
    '0'..'9': Key:=Key;
    #8: Key:=Key;
    #32: Key:=Key;
    '.': Key:=Key;
    '-': Key:=Key;
    else
      Key:=#0;
  end;
end;

procedure TfrmBaseWindow.PageControlFirstDrawTab(Control: TCustomTabControl;
  TabIndex: Integer; const Rect: TRect; Active: Boolean);
var
  R:TRect;
  CaptionText:string;
  _tabIndex, _pageCount : Integer;
begin
   R := Rect;
   //R.Left := R.Right - ACanvas.TextWidth(AMenuItem.Hint) - 15;
   _tabIndex := {(Control as TPageControl).}TabIndex;
   _pageCount := (Control as TPageControl).PageCount;
   if _tabIndex = _pageCount-1 then
    R.Right:=self.Width-2;  // zapis głupi ale rysuje gradien na koncu nawet jka zmienimy rozmiar
   DrawGradient((Control as TPageControl).Canvas, R, $00C0B0B0, clWhite, gsVertical);
   //with Sender as  TMenuItem do
   // begin
   //     MenuItemText:=Caption;
   //  end;
   CaptionText := TPageControl(Control).Pages[{(Control as TPageControl).}TabIndex].Caption + ' ';
   (Control as TPageControl).Canvas.Brush.Color := clYellow;
   (Control as TPageControl).Canvas.Brush.Style := bsClear;
   R := Rect;
   R.Left:=R.Left+8;
   DrawText((Control as TPageControl).Canvas.Handle, PChar(CaptionText), Length(CaptionText), R, 0);
end;

procedure TfrmBaseWindow.JvgPageControlFirstDrawTab(Control: TCustomTabControl;
      TabIndex: Integer; const Rect: TRect; Active: Boolean);
var
  R:TRect;
  CaptionText:string;
  _tabIndex, _pageCount : Integer;
begin
   R := Rect;
   //R.Left := R.Right - ACanvas.TextWidth(AMenuItem.Hint) - 15;
   _tabIndex := {(Control as TPageControl).}TabIndex;
   _pageCount := (Control as TJvgPageControl).PageCount;
   //if _tabIndex = _pageCount-1 then
   // R.Right:=self.Width-2;  // zapis głupi ale rysuje gradien na koncu nawet jka zmienimy rozmiar
   DrawGradient((Control as TJvgPageControl).Canvas, R, $00C0B0B0, clWhite, gsVertical);
   //with Sender as  TMenuItem do
   // begin
   //     MenuItemText:=Caption;
   //  end;
   CaptionText := TJvgPageControl(Control).Pages[{(Control as TPageControl).}TabIndex].Caption + ' ';
   (Control as TJvgPageControl).Canvas.Brush.Color := clYellow;
   (Control as TJvgPageControl).Canvas.Brush.Style := bsClear;
   R := Rect;
   R.Left:=R.Left+8;
   DrawText((Control as TJvgPageControl).Canvas.Handle, PChar(CaptionText), Length(CaptionText), R, 0);
end;

function RectInRect(const Source, Target: TRect): Boolean;
begin
  Result := (PtInRect(Target, Source.TopLeft) and PtInRect(Target, Source.BottomRight));
end;

function RectWidth(const ARect: TRect): Integer;
begin
  Result := ARect.Right - ARect.Left;
end;

function RectHeight(const ARect: TRect): Integer;
begin
  Result := ARect.Bottom - ARect.Top;
end;

function BitmapRect(const ABitmap: TBitmap): TRect;
begin
  if Assigned(ABitmap) then
    Result := Rect(0, 0, ABitmap.Width, ABitmap.Height)
  else
    Result := Rect(0, 0, 0, 0);
end;

procedure DrawGradient2(ABitmap: TBitmap; ACanvas: TCanvas; ARect: TRect; ColorFrom, ColorTo: TColor; Style: TGradientStyle);
var
  UseBitmap: Boolean;
  DrawCanvas: TCanvas;
  OldBrushHandle, NewBrushHandle: HBRUSH;

  GradientWidth, GradientHeight: Integer;
  DrawFrom, DrawTo, I, X, Y: Integer;

  ColorFromQuad, ColorToQuad: TLargeColorQuad;
  ColorValue: TColor;
  P, PF: P32bitQuadScanLine;

  procedure FillScanLine(AColor: TColor);
  var X: Integer;
  begin
    if UseBitmap then
    begin
      for X := ARect.Left to ARect.Right - 1 do
      begin
        {$R-}
        P^[X].Red := TColorQuad(AColor).Red;
        P^[X].Green := TColorQuad(AColor).Green;
        P^[X].Blue := TColorQuad(AColor).Blue;
        P^[X].Alpha := $00;
      end;
    end else
    begin
      {$IFDEF MSWINDOWS}
      NewBrushHandle := CreateSolidBrush(AColor);
      OldBrushHandle := SelectObject(DrawCanvas.Handle, NewBrushHandle);
      try
        PatBlt(DrawCanvas.Handle, ARect.Left, Y, GradientWidth, 1, PATCOPY);
      finally
        SelectObject(DrawCanvas.Handle, OldBrushHandle);
        DeleteObject(NewBrushHandle);
      end;
      {$ENDIF}
      {$IFDEF LINUX}
      DrawCanvas.Brush.Color := ColorValue;
      FillRect(Rect(ARect.Left, Y, Width, Y + 1));
      {$ENDIF}
    end;
  end;

begin
  UseBitmap := Assigned(ABitmap);
  if UseBitmap then
  begin
    DrawCanvas := ABitmap.Canvas;
    ABitmap.PixelFormat := pf32bit;
  end else
    DrawCanvas := ACanvas;

  with DrawCanvas do
  begin
    GradientWidth := ARect.Right - ARect.Left;
    GradientHeight := ARect.Bottom - ARect.Top;
    DrawFrom := ARect.Top;
    DrawTo := ARect.Bottom - 1;
    {$IFDEF LINUX}
    if UseBitmap then
      Brush.Style := bsSolid;
    {$ENDIF}
    if (ColorFrom = ColorTo) then { same color, just one drawing phase required }
    begin
      if UseBitmap then
      begin
        for I := DrawFrom to DrawTo do
        begin
          P := ABitmap.ScanLine[I];
          FillScanLine(ColorFrom);
        end;
      end else
      begin
        {$IFDEF MSWINDOWS}
        NewBrushHandle := CreateSolidBrush(ColorFrom);
        OldBrushHandle := SelectObject(Handle, NewBrushHandle);
        try
          PatBlt(Handle, 0, ARect.Top, GradientWidth, ARect.Bottom, PATCOPY);
        finally
          SelectObject(Handle, OldBrushHandle);
          DeleteObject(NewBrushHandle);
        end;
        {$ENDIF}
        {$IFDEF LINUX}
        Brush.Color := GradientStart;
        FillRect(Rect(0, ARect.Top, Width, ARect.Bottom));
        {$ENDIF}
      end;
    end else
    begin
      ColorValue := ColorToRGB(ColorFrom);
      ColorFromQuad.Red := TColorQuad(ColorValue).Red;
      ColorFromQuad.Green := TColorQuad(ColorValue).Green;
      ColorFromQuad.Blue := TColorQuad(ColorValue).Blue;

      ColorValue := ColorToRGB(ColorTo);
      ColorToQuad.Red := TColorQuad(ColorValue).Red - ColorFromQuad.Red;
      ColorToQuad.Green := TColorQuad(ColorValue).Green - ColorFromQuad.Green;
      ColorToQuad.Blue := TColorQuad(ColorValue).Blue - ColorFromQuad.Blue;

      if GradientHeight > 0 then
      begin
        case Style of
          gsVertical:
            begin
              for Y := DrawFrom to DrawTo do
              begin
                I := Y - DrawFrom;
                ColorValue := RGB2(
                  (ColorFromQuad.Red + ((ColorToQuad.Red * I) div GradientHeight)),
                  (ColorFromQuad.Green + ((ColorToQuad.Green * I) div GradientHeight)),
                  (ColorFromQuad.Blue + ((ColorToQuad.Blue * I) div GradientHeight)));
                if UseBitmap then
                  P := ABitmap.ScanLine[Y];
                try
                  FillScanLine(ColorValue);
                except
                  Exit;
                end;
              end;
            end;
          gsDiagonalLeftRight, gsDiagonalRightLeft:
            begin
              { draw first line of the gradient }
              for Y := DrawFrom to DrawTo do
              begin
                if UseBitmap then
                  P := ABitmap.ScanLine[Y];
                for X := ARect.Left to ARect.Right - 1 do
                begin
                  { I is Integer so to get decimal precision we use 1024 as multiplier.
                    Formula is "(a + b) / 2" (where a,b are percents) the precision
                    1024 is pre-divided. }
                  I := Trunc(((Y - DrawFrom) / GradientHeight + (X - ARect.Left) / GradientWidth) * 512);
                  ColorValue := RGB2(
                    (ColorFromQuad.Red + ((ColorToQuad.Red * I) div 1024)),
                    (ColorFromQuad.Green + ((ColorToQuad.Green * I) div 1024)),
                    (ColorFromQuad.Blue + ((ColorToQuad.Blue * I) div 1024)));
                  try
                    if Style = gsDiagonalRightLeft then
                      I := (ARect.Right - 1) - X + ARect.Left // flip on X axis
                    else
                      I := X;
                    if UseBitmap then
                    begin
                      P^[I].Red := TColorQuad(ColorValue).Red;
                      P^[I].Green := TColorQuad(ColorValue).Green;
                      P^[I].Blue := TColorQuad(ColorValue).Blue;
                      P^[I].Alpha := $00;
                    end else
                      Pixels[I, Y] := ColorValue;
                  except
                    Exit;
                  end;
                end;
              end;
            end;
          gsHorizontal:
            begin
              PF := nil;
              if UseBitmap then
                PF := ABitmap.ScanLine[DrawFrom];
              for X := ARect.Left to ARect.Right - 1 do
              begin
                I := X - ARect.Left;
                ColorValue := RGB2(
                  (ColorFromQuad.Red + ((ColorToQuad.Red * I) div GradientWidth)),
                  (ColorFromQuad.Green + ((ColorToQuad.Green * I) div GradientWidth)),
                  (ColorFromQuad.Blue + ((ColorToQuad.Blue * I) div GradientWidth)));
                try
                  if UseBitmap and Assigned(PF) then
                  begin
                    PF^[X].Red := TColorQuad(ColorValue).Red;
                    PF^[X].Green := TColorQuad(ColorValue).Green;
                    PF^[X].Blue := TColorQuad(ColorValue).Blue;
                    PF^[X].Alpha := $00;
                  end else
                    Pixels[X, DrawFrom] := ColorValue;
                except
                  Exit;
                end;
              end;
              { copy the first line till end }
              if UseBitmap then
              begin
                for Y := DrawFrom + 1 to DrawTo do
                  for X := ARect.Left to ARect.Right - 1 do
                  begin
                    P := ABitmap.ScanLine[Y];
                    P^[X].Red := PF^[X].Red;
                    P^[X].Green := PF^[X].Green;
                    P^[X].Blue := PF^[X].Blue;
                    P^[X].Alpha := PF^[X].Alpha;
                  end;
              end else
              begin
                CopyRect(Rect(ARect.Left, DrawFrom + 1, ARect.Right, DrawTo + 1),
                  DrawCanvas,
                  Rect(ARect.Left, DrawFrom, ARect.Right, DrawFrom + 1));
              end;
            end;
        end;
      end;
    end;
  end;
end;

function RGB2(Red, Green, Blue: Byte; Alpha: Byte = $00): TColor;
begin
  Result := (Alpha shl 24) or (Blue shl 16) or (Green shl 8) or Red;
end;

function TfrmBaseWindow.RyzykoAnalizaPN(var iRyzyko: integer; sKrotnosc, sWynikPomiaru,sTypCzynnika : String) : AnsiString;
var
   fWynikPomiaru, fKrotnosc, fWartcDop : single;
   sSaveDoZrodla :AnsiString;
begin
  try
   sSaveDoZrodla := '';
   try
    fWynikPomiaru := StrToFloat(sWynikPomiaru)*1.0;
    fKrotnosc := StrToFloat(sKrotnosc)*1.0;
    fWartcDop := fWynikPomiaru / fKrotnosc;
    if (fWartcDop > 1) and (Pos('TYP_FIZYCZNY_DRGANIA',sTypCzynnika)=0) then
      fWartcDop := Ceil(fWartcDop);
   except
      iRyzyko := 1;
      sSaveDoZrodla := 'Błąd wprowadzonych danych pomiarowych';
      Exit;
   end;
   if fWynikPomiaru<(0.5*fWartcDop) then begin
    if (sTypCzynnika = 'TYP_CHEMICZNY') or
       //(sTypCzynnika = 'TYP_BIOLOGICZNY') or
       (Pos('PYL_CALKOWITY',sTypCzynnika)>0) //or // = 'TYP_PYL_CALKOWITY') or
       //(Pos('PYL_RESPRABILNY',sTypCzynnika)>0) // = 'TYP_PYL_RESPRABILNY')
    then
      sSaveDoZrodla := ' Ps = ' + sWynikPomiaru + ' mg/m3,'
                       + chr(13) + Format(' NDS = %f mg/m3,',[fWartcDop])
                       + chr(13) +  ' Ps < 0,5 NDS';
    if(Pos('PYL_RESPRABILNY',sTypCzynnika)>0) // = 'TYP_PYL_RESPRABILNY')
    then
      sSaveDoZrodla := ' Ps = ' + sWynikPomiaru + ' włókien w cm3,'
                       + chr(13) + Format(' NDS = %f włókien w cm3,',[fWartcDop])
                       + chr(13) +  ' Ps < 0,5 NDS';

    if (sTypCzynnika = 'TYP_FIZYCZNY_DRGANIA') then
      sSaveDoZrodla := ' Wartość zmierzona = ' + sWynikPomiaru + ' m/s2,'
                       + chr(13) + Format(' wartość dopuszczlna = %f m/s2,', [fWartcDop])
                       + chr(13) + ' Wartość zmierzona < 0,5 wartości dopuszczalnej)';
    iRyzyko := 1;
   end;

   if (fWynikPomiaru>=(0.5*fWartcDop)) and (fWynikPomiaru<fWartcDop) then begin
    if (sTypCzynnika = 'TYP_CHEMICZNY') or
       //(sTypCzynnika = 'TYP_BIOLOGICZNY') or
       (Pos('PYL_CALKOWITY',sTypCzynnika)>0) //or // = 'TYP_PYL_CALKOWITY') or
       //(Pos('PYL_RESPRABILNY',sTypCzynnika)>0) // = 'TYP_PYL_RESPRABILNY')
    then
      sSaveDoZrodla := 'Ps = ' + sWynikPomiaru + ' mg/m3,'
                       + chr(13) + Format(' NDS = %f mg/m3,', [fWartcDop])
                       + chr(13) + ' 0,5 NDS < Ps < NDS';
    if (Pos('PYL_RESPRABILNY',sTypCzynnika)>0) // = 'TYP_PYL_RESPRABILNY')
    then
      sSaveDoZrodla := 'Ps = ' + sWynikPomiaru + ' włókien w cm3,'
                       + chr(13) + Format(' NDS = %f włókien w cm3,', [fWartcDop])
                       + chr(13) + ' 0,5 NDS < Ps < NDS';

    if (sTypCzynnika = 'TYP_FIZYCZNY_DRGANIA') then
      sSaveDoZrodla := ' Wartość zmierzona = ' + sWynikPomiaru + ' m/s2,'
                       + chr(13) + Format(' wartość dopuszczalna %f m/s2', [fWartcDop])
                       + chr(13) + ' wartość zmierzona < wartości douszczalnej)';
    iRyzyko := 2;
   end;

   if fWynikPomiaru>=fWartcDop then begin
    if (sTypCzynnika = 'TYP_CHEMICZNY') or
       //(sTypCzynnika = 'TYP_BIOLOGICZNY') or
       (Pos('PYL_CALKOWITY',sTypCzynnika)>0) //or // = 'TYP_PYL_CALKOWITY') or
       //(Pos('PYL_RESPRABILNY',sTypCzynnika)>0) // = 'TYP_PYL_RESPRABILNY')
    then
      sSaveDoZrodla := ' Ps = ' + sWynikPomiaru + ' mg/m3,'
                       + chr(13) + Format(' NDS = %f mg/m3,', [fWartcDop])
                       + chr(13) + ' Ps > NDS';
    if(Pos('PYL_RESPRABILNY',sTypCzynnika)>0) // = 'TYP_PYL_RESPRABILNY')
    then
      sSaveDoZrodla := ' Ps = ' + sWynikPomiaru + ' włókien w cm3,'
                       + chr(13) + Format(' NDS = %f włókien w cm3,', [fWartcDop])
                       + chr(13) + ' Ps > NDS';
    if (sTypCzynnika = 'TYP_FIZYCZNY_DRGANIA') then
      sSaveDoZrodla := ' Wartość zmierzona = ' + sWynikPomiaru + ' m/s2,'
                       + chr(13) + Format(' wartość dopuszczalna %f m/s2', [fWartcDop])
                       + chr(13) + 'Wartość zmierzona > wartości dopuszczalnej)';
    iRyzyko := 3;
   end;

   if (sTypCzynnika = 'TYP_FIZYCZNY_HALAS') then begin
    if fWynikPomiaru < 82 then begin
      sSaveDoZrodla := ' Lex(8h) = ' + sWynikPomiaru + ' dB,'
                     + chr(13) + ' NDN = 85 dB,'
                     + chr(13) + ' Lex(8h) < 82 dB (0,5 NDN)';
      iRyzyko := 1;
    end;

    if (fWynikPomiaru > 82) and (fWynikPomiaru < 85) then begin
      sSaveDoZrodla := ' Lex(8h) = ' + sWynikPomiaru + ' dB,'
                     +chr(13) + ' NDN = 85 dB,'
                     + chr(13) + ' 82 dB (0,5 NDN) < Lex(8h) < 85 dB (NDN)';
      iRyzyko := 2;
    end;

    if fWynikPomiaru >= 85 then begin
      sSaveDoZrodla := ' Lex(8h) = ' + sWynikPomiaru + ' dB,'
                     + chr(13) + ' NDN = 85 dB,'
                     + chr(13) + ' Lex(8h) > 85 dB (NDN)';
      iRyzyko := 3;
    end;
   end;

  //if sTypCzynnika = 'TYP_INNY' then begin
  //  iRyzyko := (pcPomiary.Pages[i].Controls[j] as TfrmRyzykoPomiarEdit).ComboBox1.ItemIndex+1;
  //end;

  finally
    Result := sSaveDoZrodla;
  end;

end;

end.


